package me.leiusual.sharing.ui.mine

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import androidx.lifecycle.ViewModel
import me.leiusual.sharing.pref.User
import me.leiusual.sharing.repository.UserRepository
import me.leiusual.sharing.repository.model.Data
import me.leiusual.sharing.util.extension.toLiveData
import javax.inject.Inject

/**
 * Create by leiusual on 2018/7/16
 */
class MineInfoViewModel @Inject constructor(
    userRepository: UserRepository,
    val user: User
) : ViewModel() {

  private val _avatarUpdate = MutableLiveData<String>()
  val avatarUpdate: LiveData<Data<String>> = Transformations.switchMap(_avatarUpdate) {
    userRepository.avatarUpdate(it).toLiveData()
  }

  fun avatarUpdate(filePath: String) {
    _avatarUpdate.value = filePath
  }
}